package org.ithasu.tools.data;

import org.ithasu.tools.CollectionTools;

public class EntityTools {

	protected EntityTools() {
	}

	// -- Tools ----------------------------------------

	public static <E extends Entity> boolean isValid(EntityProvider<E> provider, Long id) {
		return id == null || provider.getEntityById(id) != null;
	}

	// -- List ----------------------------------------

	public static <T extends Entity> boolean contains(EList<T> list, T entity) {
		return list != null && list.getIds().contains(entity == null ? null : entity.getId());
	}

	public static boolean isEmpty(EList<?> list) {
		return list != null && !CollectionTools.isEmpty(list.getIds());
	}

}
